package com.isoft.demo.service.impl;

import com.isoft.demo.common.ResponseData;
import com.isoft.demo.dao.EmpDao;
import com.isoft.demo.entity.CustomerInfo;
import com.isoft.demo.entity.Emp;
import com.isoft.demo.entity.Vehicle;
import com.isoft.demo.service.EmpService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Resource
    private EmpDao empDao;

    @Override
    public ResponseData addEmp(Emp emp) {
        int n = empDao.addEmp(emp);
        ResponseData rs = new ResponseData();
        List list = new ArrayList();
        if(n > 0){
            rs.setCode(0);
            rs.setMsg("添加成功");
            list.add(emp);
            rs.setData(list);
        } else{
            rs.setCode(1);
            rs.setMsg("添加失败");
        }
        return rs;
    }

    @Override
    public ResponseData deleteEmp(int eid) {
        int a = empDao.deleteEmp(eid);
        ResponseData rs = new ResponseData();
        if(a != 0){
            rs.setCode(0);
            rs.setMsg("删除成功！");
        } else{
            rs.setCode(1);
            rs.setMsg("删除失败!");
        }
        return rs;
    }

    @Override
    public ResponseData updateEmp(Emp emp) {
        int m = empDao.updateEmp(emp);
        ResponseData rs = new ResponseData();
        if(m != 0){
            rs.setCode(0);
            rs.setMsg("修改成功！");
        } else{
            rs.setCode(1);
            rs.setMsg("修改失败!");
        }
        return rs;
    }

    @Override
    public ResponseData findAllEmp() {
        List<Emp> list = empDao.findAllEmp();
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }

    @Override
    public ResponseData findByEid(Integer eid) {
        List<Emp>list = empDao.findeByEid(eid);
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        }else {
            rs.setCode(1);
            rs.setMsg("fail");
        }
        return rs;
    }

}
